{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c54c6fd0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1680*x**4 - 3360*x**3 + 2160*x**2 - 480*x + 24\n"
     ]
    }
   ],
   "source": [
    "import sympy as sp\n",
    "x = sp.Symbol('x')\n",
    "u = x**4 * (1 - x)**4\n",
    "u_fourth_derivative = sp.diff(u, x, 4)\n",
    "simplified_result = sp.simplify(u_fourth_derivative)\n",
    "print(simplified_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "359636ff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "二阶导数化简后的结果： x**2*(56*x**4 - 168*x**3 + 180*x**2 - 80*x + 12)\n"
     ]
    }
   ],
   "source": [
    "import sympy as sp\n",
    "\n",
    "# 定义符号变量\n",
    "x = sp.Symbol('x')\n",
    "\n",
    "# 定义函数\n",
    "u = x ** 4 * (1 - x) ** 4\n",
    "\n",
    "# 计算二阶导数\n",
    "second_derivative = sp.diff(u, x, 2)\n",
    "\n",
    "# 化简结果\n",
    "simplified_second_derivative = sp.simplify(second_derivative)\n",
    "\n",
    "print(\"二阶导数化简后的结果：\", simplified_second_derivative)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "277b3a17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True True False True\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "def is_bd(x):\n",
    "    return np.isclose(x[0], 1.0) | np.isclose(\n",
    "    x[0], 0.0) | np.isclose(x[1], -0.25) | np.isclose(x[1], 0.0)\n",
    "\n",
    "# testcase\n",
    "x1 = np.array([1.0, -0.25])\n",
    "x2 = np.array([0.0, 0.0])\n",
    "x3 = np.array([0.5, 0.5])\n",
    "x4 = np.array([0.5, -0.25])\n",
    "print(is_bd(x1), is_bd(x2), is_bd(x3), is_bd(x4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f426a180",
   "metadata": {},
   "outputs": [],
   "source": [
    "# f = -div(nu * (grad(u)+grad(u).T)) - pI)\n",
    "# u_x(x) = x[0]**2 * x[1]**2 + np.exp(-x[1])  # x方向\n",
    "# u_y(x) = -2/3 * x[0] * x[1]**3 + 2 - np.pi * np.sin(np.pi * x[0])  # y方向\n",
    "# p(x) = -(2 - np.pi * np.sin(np.pi * x[0])) * np.cos(2 * np.pi * x[1])\n",
    "# I为单位矩阵 计算f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "174a3c39",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.array([1, 2, 3, 4, 5])\n",
    "len(a)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fenicsx-env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
